package demo1.servlet.all;

import com.alibaba.fastjson.JSON;
import demo1.dao.Mapper.userMapper;
import demo1.dao.sql.userSql;
import demo1.pojo.users;
import demo1.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/sendAccount")
public class sendAccount extends HttpServlet {//注册之后的发送账号
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接受数据
        BufferedReader br = req.getReader();
        String params = br.readLine();//json字符串

        //转为user对象
        users users = JSON.parseObject(params,users.class);
        userService send = new userService();
        try {
            users = send.sendAccount(users);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        String userAccount = users.getUserAccount();
        String jsonString = JSON.toJSONString(userAccount);
        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
